import 'package:dio/dio.dart';

import '../models/weather_model.dart';

class WeatherUtils {
  // 单例
  static WeatherUtils instance(
          {required String appid, required String appsecret}) =>
      _instanceBase(appid: appid, appsecret: appsecret);
  static WeatherUtils? _manager;
  static WeatherUtils _instanceBase(
      {required String appid, required String appsecret}) {
    _manager ??= WeatherUtils._(appid: appid, appsecret: appsecret);
    return _manager!;
  }

  final String appid;
  final String appsecret;
  WeatherModel? weatherModel;
  WeatherUtils._({required this.appid, required this.appsecret}) {
    // getWeather();
  }
  final _dio = Dio();
  Future<WeatherModel?> getWeather() async {
    Response response = await _dio.get(
        'http://v1.yiketianqi.com/api?unescape=1&version=v63&appid=$appid&appsecret=$appsecret');
    if (response.statusCode == 200) {
      weatherModel = WeatherModel.fromJson(response.data);
    }

    return weatherModel;
  }
}
